package model;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JOptionPane;

public class Administrador {

  private String senha;
  
  public static final String NOME_ARQUIVO = "C:/Urna/senha.txt";
  static File file = new File(NOME_ARQUIVO);

  public static void setSenhaArquivo(String senha) {

    try {
      PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(new File(NOME_ARQUIVO), false)));
      writer.write(senha);
      writer.close();
    } catch (IOException e) {
      JOptionPane.showMessageDialog(null, e);
    }
  }

  public static String getSenhaArquivo() {

    String linha, senha;

    try {

      BufferedReader reader = new BufferedReader(new FileReader(NOME_ARQUIVO));
      senha = reader.readLine();
      reader.close();

      return senha;

    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }

  public static boolean arquivoExist() {
    if (file.exists()) {
      return true;
    } else {
      return false;
    }
  }
}
